#include "cfy_main.h"
#include "ui_cfy_main.h"
#include <QPushButton>
#include <QDebug>
cfy_Main::cfy_Main(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::cfy_Main)
    ,m_userPage(nullptr)
    ,m_bookPage(nullptr)
    ,m_recordPage(nullptr)
{
    ui->setupUi(this);
    initPage();
}

cfy_Main::~cfy_Main()
{
    delete ui;
}

void cfy_Main::initPage()
{
    m_userPage = new Cell_UserMgr(this);
    m_bookPage = new Cell_BookMgr(this);
    m_recordPage = new Cell_Record(this);
    ui->stackedWidget->addWidget(m_userPage);
    ui->stackedWidget->addWidget(m_bookPage);
    ui->stackedWidget->addWidget(m_recordPage);
    ui->stackedWidget->setCurrentIndex(0);

    auto l = ui->tool->children();
    for(auto it:l){
        if(it->objectName().contains("btn")){
            connect(static_cast<QPushButton*>(it),&QPushButton::clicked,this,&cfy_Main::dealMenu);
        }
    }
    m_userPage->initPage();

}
void cfy_Main::dealMenu(){
    QString str = sender()->objectName();
    do{
        if("btn_user"==str){
            m_userPage->initPage();
            ui->stackedWidget->setCurrentIndex(0);
            break;
        }
        if("btn_book"==str){
            m_bookPage->initPage();
            ui->stackedWidget->setCurrentIndex(1);
            break;
        }
        if("btn_his"==str){
            m_recordPage->initPage();
            ui->stackedWidget->setCurrentIndex(2);
            break;
        }
    }while(false);
}
